package TUILayer;

import java.text.DecimalFormat;

import ControlLayer.StatisticsCtr;
import ModelLayer.RealException;

public class StatisticsUI {

	private StatisticsCtr statisticsCtr;
	private InputParser inputParser;
	
	public StatisticsUI(InputParser inputParser) {
		statisticsCtr=new StatisticsCtr();
		this.inputParser=inputParser;
	}
	
	public void start() throws RealException 
	{
		int choise = 0;
		boolean exit = false;
		while (!exit) {
			choise = inputParser
					.getInt("\f *** Statistics Menu ***\n\n1. Customer\n2. Employee\n3. Return\n\nMake your choise: ");
			switch (choise)
			{
				case 1: 
				{
					showCustomerStatistics();
					break;
				}
				case 2:
				{
					showEmployeeStatistics();
					break;
				}
				case 3:
				{
					exit = true;
					break;
				}
			}
		}
	}

	private void showCustomerStatistics() throws RealException
	{
		int id = inputParser
			.getInt("\f ***Customer Statistics ***\n\nPlease input the ID of the customer: ");
		int[] result = inputParser
			.getMonthYear("\f ***Customer Statistics ***\n\nPlease input the month and year (mm/yyyy): ");
		int month = result[0];
		int year = result[1];
		try{
			for(String line: statisticsCtr.printStatisticsCustomer(id, month, year))
			{
				System.out.println(line);
			}
			System.out.println("Total: "+Double.valueOf(new DecimalFormat("#.##").format(statisticsCtr.getTotalCustomer(id, month, year))));
		}
		catch (RealException e)
		{
			System.out.println(e.getError());
		}
		inputParser.printReturn();
	}
	
	private void showEmployeeStatistics() throws RealException
	{
		int id = inputParser
			.getInt("\f ***Employee Statistics ***\n\nPlease input the ID of the employee: ");
		int[] result = inputParser
				.getMonthYear("\f ***Employee Statistics ***\n\nPlease input the month and year (mm/yyyy): ");
			int month = result[0];
			int year = result[1];
		try{
			for(String line: statisticsCtr.printStatisticsEmployee(id, month, year))
			{
				System.out.println(line);
			}
			System.out.println("Total: "+Double.valueOf(new DecimalFormat("#.##").format(statisticsCtr.getTotalEmployee(id, month, year))));
		}
		catch (RealException e)
		{
			System.out.println(e.getError());
		}
		inputParser.printReturn();
	}
}
